<?php
/*
** @introduction: 会员提现
** @author: 杨陈鹏
** @date: 2015-04-10 16:22
** @email: yangchenpeng@cdlinglu.com
*/
namespace Admin\Controller\Finance;


use Common\Controller\Admin\CommonController;

class WithdrawalsController extends CommonController
{
    /*
    ** @introduction: 提现申请列表
    ** @author: 杨陈鹏
    ** @email: yangchenpeng@cdlinglu.com
    */
    public function lists()
    {

        $this->page             = I('param.page',1);

        $this->nums             = I('param.nums',20);

        $this->status           = I('param.status');

        $where['is_admin']      = 'yes';
        if($this->status)
            $where['status']    = $this->status;

        $logic = D('Common/Withdrawals','Logic');

        $data = $logic::getData($where, '*', $this->page, $this->nums, "status asc,create_time desc");

        $this->data             = $data['data'];
        $this->total            = $data['total'];
        $this->display();

    }
    /*
    ** @introduction: 申请通过
    ** @author: 杨陈鹏
    ** @email: yangchenpeng@cdlinglu.com
    */
    public function pass()
    {

        $id                 = I('post.id');
        $mobile             = I('post.mobile');
        $uid                = I('post.uid');

        $logic              = D('Common/Withdrawals','Logic');

        $member_logic       = D('Common/Member','Logic');

        //获取提现金额
        $price = $logic::$model->where(['id' => $id])->getField('money');

        if($logic::$model->where(['id' => $id])->setField('status',2)){

            //减去冻结资金
            $member_logic::$model->where(['uid' => $uid])->setDec('frozen',$price);
            //减去账户余额
            $member_logic::$model->where(['uid' => $uid])->setDec('balance',$price);

            $sms = new \Think\SMS\Mobile();
            $msg = "您的申请提现已审核通过,客服已打款,请查收您的支付宝";

            $sms->send($mobile,$msg);

            $this->ajaxReturn(['code' => 200, 'msg' => '操作成功!']);

        }

        $this->ajaxReturn(['code' => 300, 'msg' => '操作失败!']);
    }
    /*
    ** @introduction: 申请拒绝
    ** @author: 杨陈鹏
    ** @email: yangchenpeng@cdlinglu.com
    */
    public function refuse()
    {
        $id                 = I('post.id');
        $mobile             = I('post.mobile');
        $uid                = I('post.uid');
        $message            = I('post.message');


        $logic              = D('Common/Withdrawals','Logic');
        $member_logic       = D('Common/Member','Logic');

        //获取提现金额
        $price = $logic::$model->where(['id' => $id])->getField('money');

        if($logic::$model->where(['id' => $id])->setField('status',3)){

            $logic::$model->where(['id' => $id])->setField('message',$message);

            //减去冻结资金
            $member_logic::$model->where(['uid' => $uid])->setDec('frozen',$price);
            $sms = new \Think\SMS\Mobile();
            $msg = "您申请的提现被拒绝,拒绝理由:".$message;

            $sms->send($mobile,$msg);

            $this->ajaxReturn(['code' => 200, 'msg' => '操作成功!']);

        }

        $this->ajaxReturn(['code' => 300, 'msg' => '操作失败!']);
    }
}